#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<functional>
using namespace std;

template <class T>
class Less
{
public:
    bool operator()(const T& a, const T& b)
    {
        return a < b;
    }
};
template <class T>
class Greater
{
public:
    bool operator()(const T& a, const T& b)
    {
        return a > b;
    }
};
namespace sty

{




    template <class T, class Container = vector<T>, class Compare = less<T> >

    class priority_queue

    {

    public:

        void AdjustUp(int child)
        {
            int parent = (child-1)/2;
            while (child > 0)
            {
                if(comp(c[parent],c[child]))
                {
                    swap(c[child], c[parent]);
                    child = parent;
                    parent = (child - 1) / 2;
                }
                else
                {
                    break;
                }
            }
        }
        void AdjustDown(int parent)
        {
            int child = (parent * 2) + 1;
            while (child < c.size())
            {
                if (child+1<c.size()&& comp(c[child],c[child+1]))
             // if (child + 1 < _con.size() && _con[child] < _con[child + 1])
                {
                    child++;
                }
                if (comp(c[parent], c[child]))
                {
                    swap(c[child], c[parent]);
                    parent = child;
                    child = (parent * 2) + 1;
                }
                else
                {
                    break;
                }
            }
        }
        priority_queue()
        {}

        //template <class InputIterator>

        //priority_queue(InputIterator first, InputIterator last)

        bool empty() const
        {
            return c.empty();
        }

        size_t size() const
        {
            return c.size();
        }

        const T& top()
        {
            return c[0];
        }

        void push(const T& x)
        {
            c.push_back(x);
            AdjustUp(c.size()- 1);
        }

        void pop()
        {
            swap(c[0], c[c.size() - 1]);
            c.pop_back();
            AdjustDown(0);
        }

    private:

        Container c;

        Compare comp;

    };

};

int main()
{
    sty::priority_queue<int,vector<int>,Greater<int>> pq;
    //sty::priority_queue<int, vector<int>, Less<int>> pq;
    pq.push(2);
    pq.push(3);
    pq.push(1);
    pq.push(5);
    pq.push(4);
    while (!pq.empty())
    {
        cout << pq.top() << " ";
        pq.pop();
    }



    return 0;
}